package com.ruibang.glass.equipment.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.common.domain.produce.WorkshopDTO;
import com.ruibang.glass.equipment.dto.SelectDTO;
import com.ruibang.glass.equipment.entity.Workshop;
import com.ruibang.glass.equipment.feign.PortalApi;
import com.ruibang.glass.equipment.mapper.WorkshopMapper;
import com.ruibang.glass.equipment.service.WorkshopService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
public class WorkshopServiceImpl extends ServiceImpl<WorkshopMapper, Workshop> implements WorkshopService {

    @Autowired
    private PortalApi portalApi;

    @Override
    public List<SelectDTO> getSelectList() {
        List<SelectDTO> selectDTOS = new ArrayList<>();
        WorkshopDTO workshopDTO = new WorkshopDTO();
        ResultBody resultBody = portalApi.queryWorkshop(workshopDTO);
        Map<String, Object> map = (Map<String, Object>) resultBody.getData();
        List<Map<String, String>> list = (List<Map<String, String>>) map.get("records");
        for (Map<String, String> map1 : list) {
            SelectDTO selectDTO = new SelectDTO();
            selectDTO.setLabel(map1.get("workshopName"));
            selectDTO.setValue(map1.get("workshopId"));
            selectDTOS.add(selectDTO);
        }
        return selectDTOS;
    }

    /**
     * 获取产线列表
     *
     * @return
     */
    @Override
    public List<SelectDTO> getProductLineList(String id) {
        List<SelectDTO> selectDTOS = new ArrayList<>();
        WorkshopDTO workshopDTO = new WorkshopDTO();
        ResultBody resultBody = portalApi.getProductLineList(id);
        List<Map<String, String>> list = (List<Map<String, String>>) resultBody.getData();
        for (Map<String, String> map : list) {
            SelectDTO selectDTO = new SelectDTO();
            selectDTO.setLabel(map.get("productLineName"));
            selectDTO.setValue(map.get("productLineId"));
            selectDTOS.add(selectDTO);
        }
        return selectDTOS;
    }

    /**
     * 获取产线列表
     *
     * @return
     */
    @Override
    public List<SelectDTO> getSelectNewList() {
        List<SelectDTO> selectDTOS = new ArrayList<>();
        WorkshopDTO workshopDTO = new WorkshopDTO();
        String id = "";
        ResultBody resultBody = portalApi.getProductLineList(id);
        List<Map<String, String>> list = (List<Map<String, String>>) resultBody.getData();
        for (Map<String, String> map : list) {
            SelectDTO selectDTO = new SelectDTO();
            selectDTO.setLabel(map.get("productLineName"));
            selectDTO.setValue(map.get("productLineId"));
            selectDTOS.add(selectDTO);
        }
        return selectDTOS;
    }

    /**
     * 获取产线列表
     *
     * @return
     */
    @Override
    public List<SelectDTO> getByProductLineAreaId(String id) {
        List<SelectDTO> selectDTOS = new ArrayList<>();
        WorkshopDTO workshopDTO = new WorkshopDTO();
        ResultBody resultBody = portalApi.getByProductLineAreaId(id);
        List<Map<String, String>> list = (List<Map<String, String>>) resultBody.getData();
        for (Map<String, String> map : list) {
            SelectDTO selectDTO = new SelectDTO();
            selectDTO.setLabel(map.get("areaName"));
            selectDTO.setValue(map.get("areaId"));
            selectDTOS.add(selectDTO);
        }
        return selectDTOS;
    }
}
